using System.Collections;
using UnityEngine;

namespace BasicScript.Component
{
	public class ShakeObject : MonoBehaviour
	{
		private bool isShake;

		private float val;

		private float time;

		public void IsShake(bool val)
		{
			isShake = true;
			time = 0f;
			StopCoroutine("StartShake");
			StartCoroutine("StartShake");
		}

		private IEnumerator StartShake()
		{
			while (isShake)
			{
				time += Time.deltaTime;
				if (time < 0.2f)
				{
					base.transform.rotation = Quaternion.Euler(0f, 0f, time * 30f);
				}
				else if ((double)time < 0.6)
				{
					base.transform.rotation = Quaternion.Euler(0f, 0f, (0.4f - time) * 30f);
				}
				else if (time < 1f)
				{
					base.transform.rotation = Quaternion.Euler(0f, 0f, (-0.8f + time) * 30f);
				}
				else if ((double)time < 1.4)
				{
					base.transform.rotation = Quaternion.Euler(0f, 0f, (1.2f - time) * 30f);
				}
				else if ((double)time < 1.6)
				{
					base.transform.rotation = Quaternion.Euler(0f, 0f, (-1.6f + time) * 30f);
				}
				else
				{
					base.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
					isShake = false;
				}
				yield return new WaitForEndOfFrame();
			}
		}
	}
}
